<template>
  <div id="promotionRecord" class="same-change-oldstyle">
    <div class="same-head-box">
      <div class="saem-seat-box">
        <div class="saem-seat-left">
          <span>当前位置：</span>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>经营设置</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/promotionList' }">促销管理</el-breadcrumb-item>
            <el-breadcrumb-item>促销金明细</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="saem-seat-right">
          <button class="same-search-btns same-search-export" @click="RefreshFun">刷新</button>
          <button class="same-search-btns" @click="returnBack">返回</button>
        </div>
      </div>
      <div class="same-search-box">
        <div>
          <div class="same-search-left">
            <div class="same-left-one">
              <span class="same-search-span same-search-fisrt">操作时间:</span>
              <el-date-picker style="width:140px" v-model="start_time" type="date" size="medium"
                value-format="yyyy-MM-dd" placeholder="开始时间"></el-date-picker>
              <div class="same-interval">至</div>
              <el-date-picker style="width:140px" v-model="end_time" type="date" size="medium" value-format="yyyy-MM-dd"
                placeholder="结束时间"></el-date-picker>
            </div>
            <div class="same-left-one" v-if="!moveShow">
              <div class="same-left-zdshwo" :hidden="!moveBtn" @click="openMore">更多查询条件<i
                  :class="[moveShow?'el-icon-arrow-up':'el-icon-arrow-down']"></i></div>
              <el-button type="primary" size="medium" @click="search()">搜索</el-button>
              <el-button type="info" size="medium" @click="reset()">重置</el-button>
            </div>
          </div>
          <div class="same-search-right"></div>
        </div>
        <!-- 搜索更多 -->
        <div>
          <div class="same-search-left new-sear-height" ref="leftHeight">
            <div class="same-left-one">
              <span class="same-search-span">促销项目:</span>
              <el-select size="medium" v-model="choosePromotion" placeholder="请选择" style="width: 140px;">
                <el-option v-for="item in promotionList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </div>
            <div class="same-left-one" :class="[moveShow?'':'new-sear-opacity']">
              <div class="same-left-zdshwo" :hidden="!moveBtn" @click="openMore">收起更多查询条件<i
                  :class="[moveShow?'el-icon-arrow-up':'el-icon-arrow-down']"></i></div>
              <el-button type="primary" size="medium" @click="search()">搜索</el-button>
              <el-button type="info" size="medium" @click="reset()">重置</el-button>
            </div>
          </div>
          <div class="same-search-right"></div>
        </div>
      </div>
    </div>

    <div class="same-table-box">
      <h4 class="same-title-box">促销金明细</h4>
      <div class="table_box">

        <div class="common-table-outer">
          <el-table class="common-table" v-loading="loading" header-cell-class-name="common-table-header-cell"
            :data="tableData" stripe>
            <el-table-column header-align="center" width="50" align="center" label="序号">
							<template slot-scope="scope">
								{{scope.$index+1+(pageNo-1)*pageSize}}
							</template>
						</el-table-column>
            <el-table-column align="center" prop="id" width="120" label="ID">
            </el-table-column>
            <el-table-column align="center" prop="name" label="促销项目">
            </el-table-column>

            <el-table-column align="center" label="金额">
              <template slot-scope="scope">
                {{scope.row.money|filterNumber}}
              </template>
            </el-table-column>


            <el-table-column align="center" label="操作人类型">
              <template slot-scope="scope">
                <span v-if="scope.row.type == 1">总后台</span>
                <span v-else-if="scope.row.type == 2">合伙人</span>
                <span v-else-if="scope.row.type == 3">水卡充值赠送</span>
                <span v-else-if="scope.row.type == 4">销售</span>
                <span v-else="">--</span>
              </template>
            </el-table-column>

            <el-table-column align="center" prop="time" label="操作时间">
            </el-table-column>

            <el-table-column align="center" prop="name" show-overflow-tooltip label="备注">
              <template slot-scope="scope">
                {{scope.row.comment||'——'}}
              </template>
            </el-table-column>


            <template slot="empty" v-if="isLoad">
              <div class="new-no-data-show">
                <img src="../../assets/images/no-data.png" alt="">
                <div>暂无相关数据</div>
              </div>
            </template>
          </el-table>

          <div class="same-page-inShow" v-if="tableData.length > 0 && isLoad">
            <el-pagination background  class="pull-right clearfix" @size-change="handleSizeChange"
              @current-change="handleCurrentChange" :current-page.sync="pageNo" :page-sizes="pageSizesList"
              :page-size="pageSize" layout="total, prev, pager, next, jumper, sizes" :total="totalDataNumber">
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    name: 'promotionRecord',
    data: function () {
      return {
        loading: false,//加载动画
        isLoad: false,//是否请求接口
        pageNo: 1,
        pageSize: 15,
        pageSizesList: [15, 30, 40, 50],
        tableData: [],      // 返回的结果集合
        totalDataNumber: 0, // 数据的总数,-----
        userAgent: '',
        promotionList: '',//促销项目选择
        start_time: '',
        end_time: '',
        choosePromotion: '',
        promotion_id: '',
        value2: '',

        moveBtn: false,//是否暂时更多查询条件按钮按钮 搜索条件控制
        moveShow: false,//是否开启动画
        scrollHeight: '',//需要监听的高度
      }
    },
    computed: {

    },
    // 初始化执行
    created: function () {
      this.$emit('gitHidden', true);//是否隐藏底部版权 true 隐藏 
      var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
      this.userAgent = userAgent;
      var that = this;
      var page = that.pageNo;			// 当前页
      var pageSize = that.pageSize;	// 每页条数
      that.promotionRecordList(page, pageSize); // 获取促销项目列表数据
    },
    inject: [
      'reload'
    ],
    methods: {
      RefreshFun() {
        // 调用reload方法，刷新整个页面
        this.reload()
      },
      //返回
      returnBack() {
        this.$router.back(-1);
      },
      promotionRecordList(page, pageSize) {
        var that = this;
        var start_time = that.start_time;	// 查询条件开始时间
        var end_time = that.end_time;	// 查询条件结束时间
        var promotion_id = that.promotion_id;	// 项目id
        that.loading = true; //开启动画
        that.isLoad = false;
        // Ajax请求
        that.$post({
          url: 'Partner/Promotion/getPromotionRecordList',
          data: {
            start_time: start_time ? start_time : '',
            end_time: end_time ? end_time : '',
            promotion_id: promotion_id,
            row: that.pageSize,
            page: that.pageNo,
          },
          success: (data) => {
            that.loading = false; //开启动画
            that.isLoad = true;
            //console.log(data);
            if (data.code == 1000) {
              //that.$message.success(data.message);
              that.tableData = data.data.data;
              that.promotionList = data.data.page.promotionList,
                that.totalDataNumber = data.data.page.total_number;
              that.pageNo = data.data.page.current_page;
            } else {
              that.$message.error(data.message);
            }

          }
        })
      },
      //重置
      reset() {
        this.start_time = "";
        this.end_time = "";
        this.promotion_id = "";
        this.pageNo = 1;
        this.choosePromotion = "";
        this.value2 = "";
        this.promotionRecordList();
      },

      //搜索
      search() {
        this.pageNo = 1;
        this.promotionRecordList();
      },
      //每页
      handleSizeChange(val) {
        var that = this;
        that.pageNo = 1;
        that.pageSize = val;            // 当前每页显示条数
        that.promotionRecordList(that.pageNo, val);      // 获取列表数据
      },
      //分页
      handleCurrentChange(val) {
        var that = this;
        var pageSize = that.pageSize;      // 每页条数
        that.pageNo = val;
        that.promotionRecordList(val, pageSize); // 获取列表数据
      },
      //项目选择
      choosePromotionFun(vlue) {
        this.promotion_id = vlue;
      },
      //此处获取高度必须在dom元素创建完成之后才能获取
      gitHeight() {
        //  let clientHeight=this.$refs.leftHeight.clientHeight;
        let scrollHeight = this.$refs.leftHeight.scrollHeight;
        this.scrollHeight = scrollHeight;
        scrollHeight <= 30 ? this.moveBtn = false : this.moveBtn = true;

      },
      openMore() {
        this.moveShow = !this.moveShow;
        this.$refs.leftHeight.style.height = this.moveShow ? this.scrollHeight + 'px' : 0 + 'px';
      },
    },
    mounted() {
      this.gitHeight();
      //监听高度变化 
      var that = this;
      window.addEventListener("resize", function () {
        let scrollHeight = that.$refs.leftHeight && that.$refs.leftHeight.scrollHeight ? that.$refs.leftHeight.scrollHeight : that.scrollHeight;
        that.scrollHeight = scrollHeight;
      });
    },
    watch: {
      // 如果 `scrollHeight` 发生改变，这个函数就会运行 此处是为了防止用户缩小屏幕导致页面显示不全
      scrollHeight: function (val) {
        this.$refs.leftHeight.style.height = this.moveShow ? this.scrollHeight + 'px' : 0 + 'px';
      }
    }
  }
</script>
<style>
  #promotionRecord {
    width: 100%;
    height: 100%;
    background: #FFFFFF;
  }
</style>